package com.ruoyi.chat.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.chat.domain.ChatUser;
import com.ruoyi.chat.domain.SysUserFriends;
import com.ruoyi.chat.service.ISysUserFriendsService;
import com.ruoyi.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class GetFriendsController {
    @Autowired
    private ISysUserFriendsService userFriendsService;

    @Autowired
    public GetFriendsController(ISysUserFriendsService userFriendsService) {
        this.userFriendsService = userFriendsService;
    }

    @PostMapping("/getFriends")
    public List<ChatUser> getFriends(@RequestParam("id") Long userId) {
        List<ChatUser> chatUsers = new ArrayList<>();
        for(SysUser sysUser : userFriendsService.selectFriendsByUserId(userId)){
            chatUsers.add(new ChatUser(sysUser));
        }
        return chatUsers;

    }


}
